package com.zrt.service;

import com.zrt.dao.DetailParseDao;
import com.zrt.dao.ParseDao;
import com.zrt.dao.ReferenceDao;
import com.zrt.dao.impl.ParseDaoImpl;
import com.zrt.domain.Reference;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SpringBootTest
public class serviceTest02 {

    @Autowired
    private ParseDao parseDao;

    @Autowired
    private DetailParseDao detailParseDao;

    @Autowired
    private ReferenceDao referenceDao;

    List<String> referencesList = new ArrayList<>();


    @Test
    public void test01(){
        String input = "D:\\pdf\\PDF\\PDF\\test\\test01.pdf";
        String input2 = "D:\\pdf\\PDF\\PDF\\test2\\test2.pdf";
        String input3 = "D:\\pdf\\PDF\\PDF\\test3\\test3-1.pdf";
        String input4 = "D:\\pdf\\PDF\\PDF\\test3\\test3-2.pdf";
        String input5 = "D:\\pdf\\PDF\\PDF\\test4\\test4.pdf";
        String input6 = "D:\\pdf\\PDF\\PDF\\test5\\test5.pdf";
        String input7 = "D:\\pdf\\PDF\\PDF\\test6\\test6.pdf";

        String parseFile = parseDao.parseFile(input7);
        String referenceContent = parseDao.parseDetailForReference(parseFile);

        detailParseDao.JudgeTheFormatOfNum(referenceContent,referencesList);

        //处理过后的references列表
        List<String> refer = detailParseDao.RemoveElementsThatAreTooShort(referencesList);

        //遍历列表和分割
        List<Reference> referenceList = detailParseDao.TraverseAndSplit(refer);
        for (Reference reference : referenceList){
            System.out.println(reference);
            referenceDao.insert(reference);
            /*System.out.println(reference.getId());
            System.out.println(reference.getName());
            System.out.println(reference.getResult());
            System.out.println(reference.getOrigin());
            System.out.println(reference.getTime());*/

            System.out.println("-------------------------------------------------");
        }


    }

    @Test
    public void testArrayTransformedToString(){
        String[] str = {"abc", "bcd", "def"};
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < str.length; i++){
            sb. append(str[i]).append(" ");
        }
        String s = sb.toString();
        System.out.println(s);
    }

    @Test
    public void testArrayTransformedToString2(){
        String[] str = {"abc", "bcd", "def"};
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < str.length; i++){
            sb. append(str[i]).append(" ");
        }
        String s = sb.toString();
        System.out.println(s);
    }

    public String testArrayTransformedToString3(String[] name){
        int k = 0;
        StringBuffer sb = new StringBuffer();
        for (int i = 0 ; i < name.length ; i++){
            if (name[i]!=null){
                k++;
            }
        }
        for (int i = 0 ; i < k ; i++){
            if (i<k-1){
                sb.append(name[i]).append(",");
            }else {
                sb.append(name[i]);
            }
        }
        return sb.toString();
    }

}
